package greetings

import "fmt"

//reverse 反转数组或者切片
func reverse(s []int) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

//将slice元素循环向左旋转n个元素的方法是三次调用reverse反转函数
func turnLeft() {

	n := 2
	s := []int{0, 1, 2, 3, 4, 5}
	reverse(s[:n])
	reverse(s[n:])
	reverse(s)
}

// 深度比较数组是否想等
func equalsString(x, y []string) bool {

	if len(x) != len(y) {
		return false
	}
	for i := range x {
		if x[i] != y[i] {
			return false
		}
	}
	return true
}

//空串合并
// nonempty returns a slice holding only the non-empty strings.
// The underlying array is modified during the call.
func nonempty(strings []string) []string {
	i := 0
	for _, s := range strings {
		if s != "" {
			strings[i] = s
			i++
		}
	}
	return strings[:i]
}

func noneemptyDemo() {

	data := []string{"one", "", "three"}
	fmt.Printf("%q\n", nonempty(data)) // `["one" "three"]`
	fmt.Printf("%q\n", data)           // `["one" "three" "three"]`
}
